var urlParamObj = $$.util.urlParamToObj();
var formModal = {};
var getVideoCallback = null;
var operateForm = function () {
    //收展分步表单
    $('body').on('click','.form-box .panel-title',function () {
        var current = $(this).find('a');
        var classStr = 'keyboard_arrow_up';
        if(current.attr('aria-expanded') == 'true'){
            classStr = 'keyboard_arrow_down';
        }
        $('.form-box .panel-title a i').text('keyboard_arrow_down');
        current.children('i').text(classStr);
        $('.form-box .panel-collapse').collapse('hide');
        current.parents('.panel-heading').next().collapse('show');
        if($('.panel-collapse[aria-expanded="true"]').length){
            $('.hide-all-form').addClass('show');
        }else{
            $('.hide-all-form').removeClass('show');
        }
        setTimeout(function () {
            $(window).resize();
        },300);
    });
    $('.hide-all-form').click(function () {
        $('.hide-all-form').removeClass('show');
        $('.form-box .panel-title a i').text('keyboard_arrow_down');
        $('.form-box .panel-collapse').collapse('hide');
    });
    //保存表单
    $('#submitForm').click(function () {
        if($(this).hasClass('disabled')) return false;
        setFollowupForms();
    });
    //表单导航条定位
    $(window).resize(function () {
        var width = $('.form-box').width();
        $('.fixed-bar').css('width',width);
    });
    //操作只读权限量表
    $('body').on('click','.type-read .panel-collapse',function () {
        $$.modal.tips('你只能查看此量表',1500);
    });
};
//获取form列表
var getFollowupForms = function () {
    if(urlParamObj.stepid){
        new followupPlan().getFollowupForms(urlParamObj.stepid,function (res, status) {
            res = JSON.parse(res);
            if(res.code == '000'){
                var resData = JSON.parse(res.data);
                (resData.step == 0) && (resData.step = '首');
                $('.step-title .num').text(resData.step);
                $('.step-title span').text(resData.title);
                formModal = resData.form;
                var formArray = resData.form.inputformdata;
                var len = formArray.length;
                var userType = urlParam.usertype;
                if(urlParamObj.phone && urlParamObj.token && urlParamObj.ctype && urlParamObj.usertype){
                    userType = urlParamObj.usertype;
                }
                var formIndex = 0;
                for(var i = 0;i < len;i ++){
                    var desHtml = '';
                    if(formArray[i].desc){
                        desHtml = '<div class="form-description">'+ decodeURI(formArray[i].desc) +'</div>';
                    }
                    var formTypeClass = '';
                    var owner = formArray[i].owner;
                    formIndex ++;
                    if(owner == userType){
                        formTypeClass = 'type-write';
                    }
                    if(owner != userType && owner != 3){
                        formTypeClass = 'type-read';
                    }
                    if(userType == 1 && owner == 3){
                        formTypeClass = 'type-write';
                    }
                    if(userType == 2 && owner == 3){
                        formTypeClass = 'type-hidden';
                        formIndex --;
                    }
                    var htmlBox = [
                        '<div class="panel panel-default '+ formTypeClass +'">',
                        '<div class="panel-heading" role="tab" id="heading-'+ i +'">',
                        '<h4 class="panel-title">',
                        '<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-'+ i +'" aria-expanded="false" aria-controls="collapse-'+ i +'">',
                        formIndex+ '、'+formArray[i].title,
                        '<i class="material-icons">&#xE313;</i>',
                        '</a>',
                        '</h4>',
                        '</div>',
                        '<div id="collapse-'+ i +'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-'+ i +'">',
                        '<div class="panel-body">',
                        desHtml,
                        '<div class="container-fluid form-input-box">',
                        '<div class="row input-box-'+ i +'">',
                        '</div>',
                        '</div>',
                        '</div>',
                        '</div>',
                        '</div>'
                    ].join('');
                    $('#accordion').append(htmlBox);
                    //获取真实图片地址
                    $('.form-description').find('img[data-srcurl]').each(function () {
                        (function (_this) {
                            var srcurl = _this.attr('data-srcurl');
                            if(srcurl && srcurl != 'undefined'){
                                new followupPlan().getRealSrc(srcurl,function (res,status) {
                                    res = JSON.parse(res);
                                    if(res.code == '000'){
                                        _this.attr('src',res.data);
                                    }
                                });
                            }
                        })($(this));
                    });
                    //获取真实视频地址
                    $('.form-description').find('embed').each(function () {
                        (function (_this) {
                            var srcurl = _this.attr('data-srcurl');
                            var width = _this.attr('width');
                            var height = _this.attr('height');
                            if(srcurl && srcurl != 'undefined'){
                                new followupPlan().getRealSrc(srcurl,function (res,status) {
                                    res = JSON.parse(res);
                                    if(res.code == '000'){
                                        _this.after('<video width="'+ width +'" height="'+ height +'" controls="controls" src="'+ res.data +'"></video>');
                                        _this.remove();
                                    }
                                });
                            }else{
                                _this.after('<video width="'+ width +'" height="'+ height +'" controls="controls" src="'+ _this.attr('src') +'"></video>');
                                _this.remove();
                            }
                        })($(this));
                    });
                    var inputs = formArray[i].inputs;
                    var inputLen = inputs.length;
                    var inputContent = '';
                    for(var j = 0;j < inputLen;j ++){
                        var formItem = inputs[j];
                        if(formItem.inputtype == 5 && formItem.type == 0){
                            inputContent = inputHtml.text(formItem.name,formItem.value);
                        }else if(formItem.inputtype == 2 && formItem.type == 0){
                            inputContent= inputHtml.date(formItem.name,formItem.value);
                        }else if(formItem.inputtype == 7 && formItem.type ==0){
                            inputContent= inputHtml.image(formItem.name,formItem.value);
                        }else if(formItem.inputtype == 6 && formItem.type ==0){
                            inputContent= inputHtml.video(formItem.name,formItem.value);
                        }else if(formItem.inputtype == 5 && formItem.type ==1){
                            inputContent= inputHtml.textarea(formItem.name,formItem.value);
                        }else if(formItem.inputtype == 3 && formItem.type ==1){
                            inputContent= inputHtml.select(formItem.name,formItem.options,formItem.value);
                        }else if(formItem.inputtype == 3 && formItem.type ==0){
                            inputContent= inputHtml.radio(formItem.name,formItem.options,formItem.value);
                        }else if(formItem.inputtype == 4 && formItem.type ==0){
                            inputContent= inputHtml.multi(formItem.name,formItem.options,formItem.value);
                        }else if(formItem.inputtype == 8 && formItem.type ==0){
                            inputContent= inputHtml.slider(formItem.name,formItem.options,+formItem.restriction.min,+formItem.restriction.max,formItem.value);
                        }else if(formItem.inputtype == 1 && formItem.type ==0){
                            inputContent= inputHtml.number(formItem.name,formItem.unit,formItem.value);
                        }
                        $('.input-box-' + i).append($(inputContent).attr('data-input-id',formItem.id).prop('outerHTML'));
                    }
                }
                //安装离开页面弹窗提示
                leavePageAlert();
                //安装material
                $.material.init();
                //安装时间插件
                timepicker();
                //安装滑块插件
                var sliderList = $('.noUi-slider-box');
                for(var i = 0;i<sliderList.length;i++){
                    var min = +$(sliderList[i]).attr('data-min');
                    var max = +$(sliderList[i]).attr('data-max');
                    var val = +$(sliderList[i]).attr('data-val');
                    noUiSlider.create(sliderList[i], {
                        range: {
                            'min': min,
                            'max': max
                        },
                        start:val,
                        step: 1,
                        margin: 20,
                        connect:'lower',
                        pips: {
                            mode: 'steps',
                            density: 100
                        }
                    });
                    sliderList[i].noUiSlider.on('change',function () {
                        var totalNum = 0;
                        var sliderArray = $(this.target).parents('.slider-container').children('div.col-sm-12');
                        var len = sliderArray.length;
                        sliderArray.each(function () {
                            totalNum += Number($(this).find('.noUi-slider-box').get(0).noUiSlider.get());
                        });
                        var averageNum = totalNum / len;
                        $(this.target).parents('.slider-container').find('.slider-total span').text(totalNum.toFixed());
                        $(this.target).parents('.slider-container').find('.slider-average span').text(averageNum.toFixed(2));
                    });
                }
                videoOperate();
                //获取量表中所有图片真实地址
                $('.form-input-box img[data-srcurl]').each(function () {
                    var _this =$(this);
                    new followupPlan().getRealSrc(_this.attr('data-srcurl'),function (res,status) {
                        res = JSON.parse(res);
                        if(res.code == '000'){
                            _this.attr('src',res.data);
                        }
                    });
                });
                //展开表单
                urlParamObj.i && $('.form-box .panel-title').eq(urlParamObj.i).click();
                $('.outer').addClass('active');
            }
        });
    }
};
//保存form列表
var setFollowupForms = function () {
    var formArray = formModal.inputformdata;
    var formLength = formArray.length;
    for(var i = 0;i < formLength;i++){
        var inputArray = formArray[i].inputs;
        var inputLength = inputArray.length;
        for(var j = 0;j < inputLength;j ++){
            var inputId = inputArray[j].id;
            var inputtype = inputArray[j].inputtype;
            var type = inputArray[j].type;
            var currentInput = $('[data-input-id="'+ inputId +'"]');
            inputArray[j].value = {};
            if(inputtype == 5 && type == 0){  //文本型
                if(currentInput.find('input').val()){
                    inputArray[j].value = {
                        textvalue : currentInput.find('input').val()
                    };
                }
            }else if(inputtype == 2 && type == 0){  //日期型
                if(currentInput.find('.input-date-box').val()){
                    inputArray[j].value = {
                        datevalue : currentInput.find('.input-date-box').val()
                    };
                }else{
                    delete inputArray[j].value;
                }
            }else if(inputtype == 7 && type == 0){ //图片
                if(currentInput.find('.img-container').length){
                    var imgArray = [];
                    currentInput.find('.img-container').each(function () {
                        imgArray.push($(this).find('img').attr('data-srcurl'));
                    });
                    inputArray[j].value = {
                        picturevalue : imgArray.join(',')
                    };
                }
            }else if(inputtype == 6 && type == 0){ //视频
                if(currentInput.find('.video-container').length){
                    var videoArray = [];
                    currentInput.find('.video-container').each(function () {
                        videoArray.push($(this).attr('data-srcurl'));
                    });
                    inputArray[j].value = {
                        videovalue : videoArray.join(',')
                    };
                }
            }else if(inputtype == 5 && type == 1){ //长文本
                if(currentInput.find('textarea').val()){
                    inputArray[j].value = {
                        textvalue : currentInput.find('textarea').val()
                    };
                }
            }else if(inputtype == 3 && type == 1){ //下拉
                if(currentInput.find('select').val()){
                    inputArray[j].value = {
                        singleoptionvalue : {
                            optionid : currentInput.parent().attr('data-id'),
                            optionname : currentInput.find('select').val()
                        }
                    };
                }
            }else if(inputtype == 3 && type == 0){  //单选
                var checkEle = currentInput.find('input[type="radio"]:checked');
                if(checkEle.length){
                    inputArray[j].value = {
                        singleoptionvalue : {
                            optionid : checkEle.parent().attr('data-id'),
                            optionname : checkEle.parent().text()
                        }
                    };
                }
            }else if(inputtype == 4 && type == 0){  //多选
                var multiOptionValue = [];
                currentInput.find(':checked').each(function () {
                    multiOptionValue.push({
                        optionid : $(this).parents('label').attr('data-id'),
                        optionname : $(this).parents('label').text()
                    });
                });
                if(multiOptionValue.length){
                    inputArray[j].value = {
                        multioptionvalue : multiOptionValue
                    };
                }
            }else if(inputtype == 8 && type == 0){  //滑块
                currentInput.children('div.col-sm-12').each(function (index) {
                    inputArray[j].options[index].optionValue = Number($(this).find('.noUi-slider-box').get(0).noUiSlider.get()).toFixed();
                });
                inputArray[j].value = {
                    textvalue : JSON.stringify({
                        total : currentInput.find('.slider-total span').text(),
                        average : currentInput.find('.slider-average span').text()
                    })
                }
            }else if(inputtype == 1 && type == 0){ //数值
                if(!!currentInput.find('input').val()){
                    inputArray[j].value = {
                        integervalue : currentInput.find('input').val()
                    };
                }else{
                    delete inputArray[j].value;
                }
            }
        }
    }
    new followupPlan().setFollowupForms(urlParamObj.stepid,formModal,function (res, status) {
        res = JSON.parse(res);
        if(res.code == '000'){
            $$.modal.tips('保存成功',1500);
        }else{
            $$.modal.tips('保存失败',1500);
        }
    })
};
//装载时间插件
var timepicker = function(){
    $('.input-date-box').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        todayBtn: true,
        minView:2,
        pickerPosition:"bottom-right"
    });
};
var inputHtml = {
    text : function (inputTitle,value) {
        return [
            '<div class="col-sm-4 input-item">',
            '<div class="form-group">',
            '<label class="col-md-4 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-6">',
            '<input type="text" class="form-control" placeholder="未填写" value="'+ (value && value.textvalue || '') +'">',
            '</div>',
            '</div>',
            '</div>'
        ].join('')
    },
    date : function (inputTitle,value) {
        var myValue = '';
        if(value) myValue = new Date(+value.datevalue+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'').split(' ')[0];
        return [
            '<div class="col-sm-4 input-item">',
            '<div class="form-group">',
            '<label class="col-md-4 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-6">',
            '<input type="text" class="form-control input-date-box"  data-date-format="yyyy-mm-dd" placeholder="年-月-日" value="'+ myValue +'"/>',
            '</div>',
            '</div>',
            '</div>'
        ].join('');
    },
    number:function (inputTitle,unit,value) {
        return [
            '<div class="col-sm-4 input-item">',
            '<div class="form-group">',
            '<label class="col-md-4 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-6">',
            '<input type="text" class="form-control" placeholder="未填写" value="'+ (value && value.integervalue || '') +'">',
            '</div>',
            '<label class="col-md-2 control-label">'+ unit +'</label>',
            '</div>',
            '</div>'
        ].join('');
    },
    image:function (inputTitle,value) {
        var imgHtml = '';
        if(value && value.picturevalue){
            var imgSrcArray = value.picturevalue.split(',');
            for(var i =0,len = imgSrcArray.length;i<len;i++){
                imgHtml += '<div class="img-container"><span class="del-form">×</span><img data-srcurl="'+ imgSrcArray[i] +'" src="../../img/loading.gif"/></div>';
            }
        }
        return [
            '<div class="col-sm-12 img-vedio" id="addImg">',
            '<div class="form-group">',
            '<label class="col-md-12 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-12">',
            imgHtml,
            '<div class="add-container upload-img"><i class="material-icons">&#xE145;</i><input type="file" accept="image/*" ></div>',
            '</div>',
            '</div>',
            '</div>'
        ].join('');
    },
    video:function (inputTitle,value) {
        var videoHtml = '';
        if(value && value.videovalue){
            var videoSrcArray = value.videovalue.split(',');
            for(var i =0,len = videoSrcArray.length;i<len;i++){
                videoHtml += '<div data-click="false" class="video-container" data-srcurl="'+ videoSrcArray[i] +'"><span class="del-form">×</span><span class="media-play"><i class="material-icons">&#xE039;</i></span></div>';
            }
        }
        return [
            '<div class="col-sm-12" id="addVedio">',
            '<div class="form-group">',
            '<label class="col-md-12 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-12">',
            videoHtml,
            '<div class="add-container upload-video"><i class="material-icons">&#xE145;</i><input type="file" accept="video/*"></div>',
            '</div>',
            '</div>',
            '</div>'
        ].join('');
    },
    textarea:function (inputTitle,value) {
        return [
            '<div class="col-sm-12 input-item">',
            '<div class="form-group">',
            '<label class="col-md-2 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-10">',
            '<textarea class="form-control">'+ (value && value.textvalue || '') +'</textarea>',
            '</div>',
            '</div>',
            '</div>'
        ].join('');
    },
    select:function (inputTitle,options,value) {
        var optionStr ='';
        for(var i =0,len=options.length;i<len;i++){
            var optionHtml = '<option>'+ options[i].optionname +'</option>';
            if(value && value.singleoptionvalue && value.singleoptionvalue.optionname == options[i].optionname){
                optionHtml = '<option selected>'+ options[i].optionname +'</option>';
            }
            optionStr += optionHtml;
        }
        return [
            '<div class="col-sm-4 input-item">',
            '<div class="form-group">',
            '<label class="col-md-6 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-6">',
            '<select class="form-control">'+ optionStr +'</select>',
            '</div>',
            '</div>',
            '</div>'
        ].join('');
    },
    radio:function (inputTitle, options,value) {
        var optionStr ='';
        for(var i =0,len=options.length;i<len;i++){
            var radioHtml = '<input type="radio" name="'+ inputTitle +'">';
            if(value && value.singleoptionvalue && options[i].optionid == value.singleoptionvalue.optionid){
                radioHtml = '<input type="radio" name="'+ inputTitle +'" checked>';
            }
            optionStr += [
                '<div class="col-md-4"><div class="radio radio-primary">',
                '<label data-id="'+ options[i].optionid +'">',
                radioHtml,
                options[i].optionname,
                '</label>',
                '</div></div>'
            ].join('');
        }
        return [
            '<div class="col-sm-12 input-item">',
            '<div class="form-group" style="margin-top:0">',
            '<label class="col-md-12 control-label" style="margin-bottom: 15px">'+ inputTitle +'</label>',
            '<div class="col-md-12">',
            optionStr,
            '</div>',
            '</div>',
            '</div>'
        ].join('');
    },
    multi:function (inputTitle, options,value) {
        var optionStr ='';
        for(var i =0,len=options.length;i<len;i++){
            var mulOptionHtml = '<input type="checkbox"> ' + options[i].optionname;
            if(value && value.multioptionvalue){
                for(var j = 0,mulLen = value.multioptionvalue.length;j<mulLen;j++){
                    if(value.multioptionvalue[j].optionid == options[i].optionid){
                        mulOptionHtml = '<input type="checkbox" checked> ' + options[i].optionname;
                        break;
                    }
                }
            }
            optionStr += [
                '<label class="col-md-2" data-id="'+ options[i].optionid +'">',
                mulOptionHtml,
                '</label>'
            ].join('');
        }
        return [
            '<div class="col-sm-12 input-item">',
            '<div class="form-group">',
            '<label class="col-md-12 control-label">'+ inputTitle +'</label>',
            '<div class="col-md-12 checkbox">',
            optionStr,
            '</div>',
            '</div>',
            '</div>'
        ].join('');
    },
    slider:function (inputTitle, options, min, max,value) {
        var optionStr ='';
        for(var i =0,len=options.length;i<len;i++){
            optionStr += [
                '<div class="col-sm-12">',
                '<div class="form-group">',
                '<label class="col-md-12 control-label">'+ options[i].optionname +'</label>',
                '<div class="col-md-12 noUI-slider-container">',
                '<div class="slider shor noUi-slider-box" data-min="'+ min +'" data-max="'+ max +'" data-val="'+ (options[i].optionValue || 1) +'"></div>',
                '</div>',
                '</div>',
                '</div>'
            ].join('');
        }
        return [
            '<div class="col-sm-12 slider-container input-item">',
            '<p class="col-sm-12 slider-title">'+ inputTitle +'</p>',
            optionStr,
            '<p class="col-sm-12 text-right calc-num">' ,
            '<span class="slider-total">总计：<span>'+ (value && value.textvalue && JSON.parse(value.textvalue).total || "-") +'</span> 分</span>',
            '&emsp;&emsp;<span class="slider-average">平均：<span>'+ (value && value.textvalue && JSON.parse(value.textvalue).average || "-") +'</span> 分</span>',
            '</p>',
            '</div>'
        ].join('');
    }
};
//离开页面提示
var leavePageAlert = function () {
    if(!$('.form-box .type-write').length || urlParamObj.status == '2'){
        $('#submitForm').addClass('disabled');
        return false;
    }
    //关闭页面、刷新页面
    var tempFunction =  function(event) {event.returnValue = '';};
    window.addEventListener("beforeunload",tempFunction);
    //监听a标签
    $('body').on('click','a',function (e) {
        var href = $(this).attr('href');
        if((href.indexOf('#') != 0) && (href != 'javascript:;') && (href != 'javascript:void(0);') && (href != 'javascript:void(0)')){
            e.preventDefault();
            $$.modal.confirm('你即将离开页面，请确保数据已保存','留下','离开',function () {
                window.removeEventListener("beforeunload",tempFunction);
                location.href = href;
            });
        }else{
            window.removeEventListener("beforeunload",tempFunction);
            setTimeout(function () {
                window.addEventListener("beforeunload",tempFunction);
            },500);
        }
    })
};
//视频处理相关
var videoOperate = function () {
    //上传视频
    var ua = window.navigator.userAgent.toLowerCase();
    if(urlParamObj.phone && urlParamObj.token && urlParamObj.ctype && urlParamObj.usertype){
        $('.upload-video').click(function (e) {
            var _this = $(this);
            e.preventDefault();
            if(ua.indexOf("android") > -1){
                LeleyBridge.callMethod('FollowUpWebActivity', 'openRecorderVideo', {}, function(res) {
                    if(res.status && res.status.code == 0 ){
                        _this.before('<div data-click="false" class="video-container" data-srcurl="'+ res.data.path +'"><span class="del-form">×</span><span class="media-play"><i class="material-icons">&#xE039;</i></span></div>');
                    }
                });
            }else if(ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1){
                Leley.callCamera();
                getVideoCallback = function(res) {
                    res = JSON.parse(res);
                    if(res.status && res.status.code == 0 ){
                        _this.before('<div data-click="false" class="video-container" data-srcurl="'+ res.data.path +'"><span class="del-form">×</span><span class="media-play"><i class="material-icons">&#xE039;</i></span></div>');
                    }
                }
            }
        });
    }else{
        $('.upload-video').change(function () {
            var _this = $(this);
            _this.append('<div class="loading-box"><img class="loading" src="../../img/loading.gif" /><span class="middle"></span></div>');
            new followupPlan().uploadFile(_this.find('input[type="file"]').get(0),function (res,status) {
                res = JSON.parse(res);
                if(res.code == '000'){
                    _this.find('.loading-box').remove();
                    _this.before('<div data-click="true" class="video-container" data-srcurl="'+ JSON.parse(res.data).srcurl +'" data-url="'+ JSON.parse(res.data).url +'"><span class="del-form">×</span><span class="media-play"><i class="material-icons">&#xE039;</i></span></div>');
                }
            });
        });
    }
    //播放视频
    $('body').on('click','.video-container',function () {
        var current = $(this);
        var srcurl = '';
        if(current.attr('data-click') == 'false'){
            srcurl = current.attr('data-srcurl');
            current.attr('data-click','true');
            //获取真实视频地址
            new followupPlan().getRealSrc(srcurl,function (res,status) {
                res = JSON.parse(res);
                if(res.code == '000'){
                    srcurl = res.data;
                    current.attr('data-url',srcurl);
                    showVideoModal(srcurl);
                }
            });
        }else{
            srcurl = current.attr('data-url');
            showVideoModal(srcurl);
        }
        function showVideoModal(src) {
            $('#playVideoModal').remove();
            if (window.screen && screen.width) {
                var screenWidth = screen.width;
                var width = 0;
                if (screenWidth > 960) {
                    width = 400;
                } else if (screenWidth > 375) {
                    width = 320;
                }else{
                    width = '100%';
                }
            }
            $('body').append([
                '<div class="modal fade top" id="playVideoModal">',
                '<div class="modal-dialog">',
                '<div class="modal-content" style="background: #000;">',
                '<div class="modal-body text-center">',
                '<video src="'+ src +'" width= "'+ width +'" controls preload></video>',
                '</div>',
                '</div>',
                '</div>',
                '</div>'
            ].join(''));
            $('#playVideoModal').modal('show');
        }
        return false;
    });
    //删除视频
    $('body').on('click','.video-container .del-form',function () {
        $(this).parents('.video-container').remove();
        return false;
    })
};
//图片处理相关
var imageOperate = function () {
    //上传图片
    $('body').on('change','.upload-img',function () {
        var _this = $(this);
        _this.append('<div class="loading-box"><img class="loading" src="../../img/loading.gif" /><span class="middle"></span></div>');
        new followupPlan().uploadFile(_this.find('input[type="file"]').get(0),function (res,status) {
            res = JSON.parse(res);
            _this.find('.loading-box').remove();
            if(res.code == '000'){
                _this.before('<div class="img-container"><span class="del-form">×</span><img data-srcurl="'+ JSON.parse(res.data).srcurl +'" src="'+ JSON.parse(res.data).url +'"/></div>');
            }else{
                $$.modal.tips('上传失败',1500);
            }
        });
    });
    //查看大图
    $('body').on('click','.img-container',function () {
        $('#BigImageModal').remove();
        $('body').append([
            '<div class="modal fade" id="BigImageModal">',
            '<div class="modal-dialog">',
            '<div class="modal-content" style="background: #000;">',
            '<div class="modal-body text-center">',
            '<img src="'+ $(this).find("img[data-srcurl]").attr("src") +'" style="max-width: 100%" alt="">',
            '</div>',
            '</div>',
            '</div>',
            '</div>'
        ].join(''));
        $('#BigImageModal').modal('show');
        setTimeout(function () {
            $('#BigImageModal').find('.modal-dialog').css('margin-top',(($(window).height() - $('#BigImageModal').find('.modal-dialog').height())/2));
        },180);
        return false;
    });
    //关闭大图
    $('body').on('click','#BigImageModal',function () {
        $('#BigImageModal').modal('hide');
    });
    //删除图片
    $('body').on('click','.img-container .del-form',function () {
        $(this).parents('.img-container').remove();
        return false;
    })
};
$(function () {
    operateForm();
    getFollowupForms();
    if(urlParamObj.status && urlParamObj.status == '2'){
        $('#submitForm').addClass('disabled');
    }
    imageOperate();
});